home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / bbs_game / sdl212x.zip / MODULE.C < prev    next >
C/C++ Source or Header  |  1996-05-15  |  24KB  |  704 lines

  1. //////////////////////////////////////////////////////////////////////////
  2. // MODULE.C: An example for a module run from one of stardock loco's expansion
  3. // slots.  Feel free to use this code for any stardock loco modules.
  4.  
  5. // This was compiled using Borland Turbo C++ version 3.0
  6. // This will _not_ compile without Brian Pirie's Opendoors odoorh.lib (huge model)
  7.  
  8. // Also feel free to upgrade my version of Guido's Black Market.
  9. // Note: It is crucial to the game that they be able to upgrade their
  10. // armor and weapon strength at the higher levels!  Make sure to keep that
  11. // if you make a better black market.
  12.  
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Do not distribute any modules that use unregistered serial comm libraries!
  15. /////////////////////////////////////////////////////////////////////////////
  16.  
  17. // Ok, enough of that, here's how I call this program.  This is the actual
  18. // code that I use to spawn _from_ stardock loco for anyone that goes into the
  19. // black market:    i.e. blkmkt1.exe
  20. //
  21. // Note:  This is nearly identical to, and works the same way from any expansion
  22. // slots in the game.  The 'Yards expansion slots gets the filepath from
  23. // the module.lst, and does the same thing as below.  The other slots
  24. // are run by using _dos_find_first to find the first occurance of the first
  25. // two letters.  See sd_devlp.txt for all the gruesome details.
  26. //
  27. // any od_control structure usage is from Brian Pirie's Opendoors 6.0 serial
  28. // comm library.  Get his program and register it.
  29. //
  30. // od_control.info_path is the path to the door.sys, or whatever the file
  31. // is that has the BBS information on the user.
  32. //
  33. //
  34. //   Make sure it's there, or look for an upgrade to blkmkt2.exe etc.
  35. //
  36. //    if( _dos_findfirst("blkmkt?.exe",_A_NORMAL,&ffblk) ==0)
  37. //        {
  38. //        update_player_file();  //update the player file before spawn
  39. //
  40. //            od_spawnvpe(P_WAIT,filepath,_argv,NULL);
  41. //        check_it();       //make sure they aren't dead.
  42. //                              - this is for real modules.
  43. //                                A person can't die in the black market.
  44. //        }
  45. //////////////////////////////////////////////////////////////////////////
  46. //
  47. //                         Guido's Black Market
  48. //                Formerly known as Indelgo's Black Market.
  49. //////////////////////////////////////////////////////////////////////////
  50. #include <string.h>
  51. #include <stdlib.h>
  52. #include <stdio.h>
  53. #include <dos.h>
  54. #include <time.h>
  55.  
  56. #include "opendoor.h"
  57. //from Brian Pirie's Opendoors 6.0 serial comm library
  58. //contains all the functions and structures necessary for comm routines.
  59.  
  60. //Update, I've begun using 6.0.  New things shall arise.  See the web site:
  61. //  http://www.starlink.com/~jam/ (Follow the links)
  62. //  http://www.starlink.com/~alanen  (My weird page)
  63.  
  64. #include <ctype.h>
  65. #include <errno.h>
  66.  
  67. //see sd_devlp.txt for all the information on this stuff.
  68. #define MAX 2
  69. #define MAXNAME  30
  70. #define    MAXBBSNAME 36
  71. #define    MAXWEAPONNAME 20
  72. #define    MAXARMORNAME 20
  73. #define MAXSTANDARDLONG 10
  74. #define MAXSTANDARDINT 4  //standard integer
  75. #define WAIT_FOR_FILE         10       /* Time to wait for access to file */
  76. FILE *OpenExclusiveFile(char *pszFileName, char *pszAccess, time_t Wait); //exclusive file access
  77. void update_player_file(void);
  78. void r_player_file(void);
  79. void WaitForEnter(void);
  80. void More(void);
  81. void door(void);
  82. void indelgos_bm(void);    //the module
  83. void change(void);    //formats numbers to nice numbers with commas
  84.  
  85. struct on_line_player   //See the sd_devlp.txt for further explanations!!
  86.     {
  87.     int on_now;
  88.     char name[MAXNAME+1];
  89.     char bbs_name[MAXBBSNAME+1];
  90.     int living;      //if alive = 1
  91.     char killer[MAXNAME+1];     //who killed player
  92.     int location;    //1 if in TP's, 2 if in pod
  93.     long lifepoints;
  94.     long lifepointsttl;
  95.  
  96.     char weapon[MAXWEAPONNAME+1];
  97.     unsigned long weapon_energy;
  98.     int weapon_strength;
  99.     unsigned long max_packs;
  100.     int weapon_status;
  101.     unsigned long weapon_cost;
  102.  
  103.     char armor[MAXARMORNAME+1];
  104.     unsigned long armor_strength;
  105.     int armor_status;
  106.     unsigned long armor_cost;
  107.  
  108.     unsigned long credits;
  109.     unsigned long bank_credit;
  110.  
  111.     int pod;
  112.  
  113.     int ship;
  114.     char ship_name[MAXNAME+1];
  115.     int ship_type;
  116.     int mt;              //matter transmitter
  117.     int arkon_bomb;
  118.  
  119.     //*extra data:
  120.     int level;
  121.     unsigned long experience;
  122.     int kills;
  123.     int droids;
  124.     int passkey;
  125.  
  126.    //assorted stuff *global* //
  127.     int on_off;    //on off for off-line droid attack
  128.     //reset daily by extern:   //from defaults....
  129.     int sickbay_closed;        //killed staff
  130.     int bank_closed;           //angered guido
  131.     int pickpocket;            //picked N. Wetlys pocket
  132.     int tipcnt;                //max tips taken
  133.     int owns;                 //1 owns weapon shop, 2 owns armor shop
  134.     int fights;                //fights per day 30?
  135.     int last_played;           //stardock days running
  136.     };
  137.  
  138. struct on_line_player current;
  139.  
  140. struct player
  141.     {
  142.     char on_now[MAXSTANDARDINT+1];
  143.     char name[MAXNAME+1];
  144.     char bbs_name[MAXBBSNAME+1];
  145.     char living[MAXSTANDARDINT+1];      //if alive = 1
  146.     char killer[MAXNAME+1];
  147.     char location[MAXSTANDARDINT+1];
  148.     char lifepoints[MAXSTANDARDLONG+1];
  149.     char lifepointsttl[MAXSTANDARDLONG+1];
  150.  
  151.     char weapon[MAXWEAPONNAME+1];
  152.     char weapon_energy[MAXSTANDARDLONG+1];
  153.     char weapon_strength[MAXSTANDARDINT+1];
  154.     char max_packs[MAXSTANDARDLONG+1];
  155.          //if they have a weapon = 1
  156.     char weapon_status[MAXSTANDARDINT+1];
  157.     char weapon_cost[MAXSTANDARDLONG+1];
  158.  
  159.     char armor[MAXARMORNAME+1];
  160.     char armor_strength[MAXSTANDARDLONG+1];
  161.     char armor_status[MAXSTANDARDINT+1];        //if they have armor = 1
  162.     char armor_cost[MAXSTANDARDLONG+1];
  163.  
  164.     char credits[MAXSTANDARDLONG+1];
  165.     char bank_credit[MAXSTANDARDLONG+1];
  166.  
  167.     char pod[MAXSTANDARDINT+1];
  168.  
  169.     char ship[MAXSTANDARDINT+1];
  170.     char ship_name[MAXNAME+1];
  171.     char ship_type[MAXSTANDARDINT+1];
  172.     char mt[MAXSTANDARDINT+1];
  173.     char arkon_bomb[MAXSTANDARDINT+1];
  174.  
  175.     char level[MAXSTANDARDINT+1];
  176.     char experience[MAXSTANDARDLONG+1];
  177.     char kills[MAXSTANDARDINT+1];
  178.     char droids[MAXSTANDARDINT+1];
  179.     char passkey[MAXSTANDARDINT+1];
  180.  
  181.      //globals
  182.     char on_off[MAXSTANDARDINT+1];
  183.     char sickbay_closed[MAXSTANDARDINT+1];
  184.     char bank_closed[MAXSTANDARDINT+1];
  185.     char pickpocket[MAXSTANDARDINT+1];
  186.     char tipcnt[MAXSTANDARDINT+1];
  187.     char owns[MAXSTANDARDINT+1];
  188.     char fights[MAXSTANDARDINT+1];
  189.     char last_played[MAXSTANDARDINT+1];
  190.     };
  191.  
  192.  
  193. int playerfound=0;
  194. char door_sys_name[MAXBBSNAME+1];
  195. int record_count;
  196. char number[14];  //for formatted credit amounts and such.  See change();
  197.  
  198.  
  199. //NEW:
  200. char sdpath[80];  //Path to SDL's player.lst.  It is contained in sdpath.dat
  201.  
  202.  
  203.  
  204.  
  205. //main()/WinMain() 32 bit is:
  206. //Straight out of Brian Pirie's example, ez_vote.c from Opendoors 6.0
  207. //This is his wording, coding, etc.  It works.  So I changed to his.
  208. //You don't have to include this for now, but it may help later when I
  209. //create a 32 bit version.  (Real one. :)
  210. /* main() or WinMain() function - Program execution begins here. */
  211. #ifdef ODPLAT_WIN32
  212. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  213.    LPSTR lpszCmdLine, int nCmdShow)
  214. #else
  215. int main(int argc, char *argv[])
  216. #endif
  217. {
  218.  
  219. #ifdef ODPLAT_WIN32
  220.    /* In Windows, pass in nCmdShow value to OpenDoors. */
  221.    od_control.od_cmd_show = nCmdShow;
  222.  
  223.    /* Ignore unused parameters. */
  224.    (void)hInstance;
  225.    (void)hPrevInstance;
  226. #endif
  227.  
  228.  
  229.    /* Set program's name for use by OpenDoors. */
  230.  
  231.    //Change this for yours please...<G>!
  232.    strcpy(od_control.od_prog_name, "Stardock Loco WIN95/NT - DOS 16bit");
  233.    strcpy(od_control.od_prog_version, "Version 1 BETA");
  234.    strcpy(od_control.od_prog_copyright, "Copyright 1995-1996 by Aaron Alanen");
  235.  
  236.    /* Call the standard command-line parsing function. You will probably     */
  237.    /* want to do this in most programs that you write using OpenDoors, as it */
  238.    /* automatically provides support for many standard command-line options  */
  239.    /* that will make the use and setup of your program easer. For details,   */
  240.    /* run the vote program with the /help command line option.               */
  241. #ifdef ODPLAT_WIN32
  242.    od_parse_cmd_line(lpszCmdLine);
  243. #else
  244.    od_parse_cmd_line(argc, argv);
  245. #endif
  246.  
  247.    /* Enable use of OpenDoors configuration file system. */
  248.    od_control.od_config_file = INCLUDE_CONFIG_FILE;
  249.  
  250.    /* Set function to process custom configuration file lines. */
  251.    //od_control.od_config_function = CustomConfigFunction;
  252.  
  253.    /* Include the OpenDoors multiple personality system, which allows    */
  254.    /* the system operator to set the sysop statusline / function key set */
  255.    /* to mimic the BBS software of their choice.                         */
  256.    od_control.od_mps = INCLUDE_MPS;
  257.  
  258.    /* Include the OpenDoors log file system, which will record when the */
  259.    /* door runs, and major activites that the user performs.            */
  260.    od_control.od_logfile = INCLUDE_LOGFILE;
  261.  
  262.    /* Set filename for log file. If not set, DOOR.LOG will be used by */
  263.    /* default.                                                        */
  264.    strcpy(od_control.od_logfile_name, "SDL.LOG");
  265.  
  266.    /* Set function to be called before program exits. */
  267.    od_control.od_before_exit = BeforeExitFunction;
  268.  
  269.    /* Initialize OpenDoors. This function call is optional, and can be used */
  270.    /* to force OpenDoors to read the door informtion file and begin door    */
  271.    /* operations. If a call to od_init() is not included in your program,   */
  272.    /* OpenDoors initialization will be performed at the time of your first  */
  273.    /* call to any OpenDoors function. */
  274.    od_init();
  275.  
  276. strncpy(door_sys_name,od_control.user_name,sizeof(od_control.user_name));
  277. door();      //main part of the IGM
  278. return 0;
  279. }
  280.  
  281.  
  282.         ////////YOUR IGM HERE///////////
  283.  
  284. void door(void)
  285. {        //Get the path for the player list.  I created this so that
  286.      //you can put your IGM into a different directory, if it is
  287.      //an IGM that goes into the Other Places.  If it is a drop in
  288.      //for the BAnk or TP's, this won't matter.
  289.  
  290. if( (fptr = OpenExclusiveFile("sdpath.dat", "rb", WAIT_FOR_FILE))==NULL)
  291.     {
  292.     od_clr_scr();
  293.     od_printf("\n\r\n\r`bright red`ERROR:");
  294.     od_printf("\n\r`red`You must run SDPATH.EXE or the IGM's may not work");
  295.     od_printf("\n\rcorrectly.  Using current directory for player.lst`cyan`");
  296.     od_printf("\n\rIf you are not the SySop, please notify your SySop of this error.");
  297.     strcpy(sdpath,"player.lst");
  298.     WaitForEnter();
  299.     }
  300. else    { fgets(sdpath,79,fptr); fclose(fptr);}
  301.  
  302. r_player_file();   //read the player file, make sure they are there.
  303. if(playerfound==1)     //when it's found do the IGM
  304. {
  305. indelgos_bm();      //run the IGM  (originally Indelgo's Black Market)
  306. update_player_file();     //save the changes made, if any.
  307. }
  308. else
  309.     {
  310.     od_printf("\n\rPlayer not found!");  //bad error!
  311.     od_printf("Name Error.");
  312.     WaitForEnter();
  313.     }
  314. }
  315.  
  316.  
  317.  
  318. void indelgos_bm(void)
  319. {
  320. char numstr[10];
  321. unsigned long total=0;
  322. unsigned long amt;
  323. unsigned long cost;
  324. char choice,choice2;
  325. do{
  326. od_clr_scr();
  327. od_send_file("gbmkt.ans");
  328. sprintf(number,"%ld",current.credits);
  329. change();
  330. od_printf("\n\r`cyan`Your Credits: $`green`%s`cyan`.",number);
  331. od_printf("\n\rMake your choice: ");
  332. choice=od_get_answer("BDUIX\n\r");
  333. switch(choice)
  334.     {
  335.     case 'D':
  336.     case 'B':
  337.         amt=current.level*100000;
  338.         sprintf(number,"%ld",amt);
  339.         change();
  340.         od_printf("\n\rAh, you'd like some `white`droids`cyan`, eh?  They are $`green`%s`cyan` apiece.",number);
  341.         total=current.credits/amt;
  342.         sprintf(number,"%ld",total);
  343.         change();
  344.         od_printf("\n\rYou can buy `bright cyan`%s`cyan` with your credits.",number);
  345.         od_printf("\n\r`bright cyan`How many would you like? `cyan`[0 to exit] ");
  346.         od_input_str(numstr,4,'0','9');
  347.         amt=atoi(numstr);
  348.         if(amt>0)
  349.             {
  350.             cost=amt*(current.level*100000);
  351.             if(cost>current.credits)
  352.                 od_printf("`yellow`\n\rYou haven't enough money..`cyan`");
  353.             else
  354.                 {
  355.                 sprintf(number,"%ld",amt);
  356.                 change();
  357.                 od_printf("\n\rOk, you've bought `green`%s`cyan` droids.",number);
  358.                 od_printf("\n\rI hope you use them `red`wisely`cyan`...");
  359.                 current.credits-=cost;
  360.                 current.droids+=amt;
  361.                 }
  362.             }
  363.             WaitForEnter();
  364.             break;
  365.         case 'U':
  366.             if(current.armor_strength<350000)
  367.                 {
  368.                 od_printf("\n\rUpgrade that armor?  `bright cyan`NEVER!`cyan`");
  369.                 od_printf("\n\rGive me something to work with here!!!");
  370.                 }
  371.             else
  372.             {
  373.             od_printf("\n\rIt costs $`bright cyan`100,000,000`cyan` to upgrade your armor");
  374.             sprintf(number,"%ld",current.armor_strength);
  375.             change();
  376.             od_printf("\n\rfrom `bright cyan`%s`cyan` to ",number);
  377.             sprintf(number,"%ld",(current.armor_strength+50000));
  378.             change();
  379.             od_printf("`bright cyan`%s`cyan`.",number);
  380.             od_printf("\n\r`bright cyan`Do you wish to upgrade your armor? [Y/N]`cyan`");
  381.             choice2=od_get_answer("YN\n\r");
  382.             switch(choice2)
  383.                 {
  384.                 case 'N':
  385.                     break;
  386.                 case 'Y':
  387.                 default:
  388.                     if(current.armor_strength<2000000000)//<-this has changed.  Heck if I remember. <G>
  389.                         {
  390.                         if(current.credits>=100000000)
  391.                             {
  392.                             current.credits-=100000000;
  393.                             current.armor_strength+=50000;
  394.                             sprintf(number,"%ld",current.armor_strength);
  395.                             change();
  396.                             od_printf("\n\rOk, your armor has been upgraded to `bright cyan`%s!`cyan`",number);
  397.                             }
  398.                         else
  399.                             od_printf("\n\rYou don't have enough money!");
  400.                         }
  401.                     else
  402.                         od_printf("\n\rSorry, your armor is MAXED!!!!");
  403.  
  404.                   }
  405.             }
  406.         WaitForEnter();
  407.         break;
  408.         case 'I':
  409.             if(current.weapon_strength<1000) //<-this may be different now.
  410.                 od_printf("\n\rWe only upgrade `bright cyan`Crowley's Cannons`cyan` or better here!");
  411.             else
  412.             {
  413.             od_printf("\n\rI'll give you a great deal on an `bright cyan`O.S.S.C Overcharge Pack!`cyan`");
  414.             od_printf("\n\rOnly cost you $`bright cyan`100,000,000`cyan` for an increase from `bright cyan`%d`cyan` to `bright cyan`%d`cyan`!",current.weapon_strength,current.weapon_strength+3);
  415.             od_printf("\n\r`bright cyan`Do you wish to buy one? [Y/N]`cyan` ");
  416.             choice2=od_get_answer("YN\n\r");
  417.             switch(choice2)
  418.                 {
  419.                 case 'N':
  420.                     break;
  421.                 case 'Y':
  422.                 default:
  423.                     if(current.weapon_strength<125)
  424.                         {
  425.                         if(current.credits>=100000000)
  426.                             {
  427.                             od_printf("\n\rOk, your `bright cyan`%s`cyan` has been upgraded!",current.weapon);
  428.                             current.credits-=100000000;
  429.                             current.weapon_strength+=3;
  430.                             }
  431.                         else
  432.                             od_printf("\n\rYou don't have enough money!");
  433.                         }
  434.                     else
  435.                         od_printf("\n\rSorry, your weapon is MAXED!!!!");
  436.                 }
  437.             }
  438.         WaitForEnter();
  439.         break;
  440.         case 'X':
  441.         default:
  442.             choice='X';
  443.             break;
  444.         }
  445. }while(choice!='X');
  446. }
  447.  
  448.  
  449. void r_player_file(void)        //initial read of the player file
  450. {                               //see sd_devlp.txt for more info.
  451. int k;
  452.  
  453. struct player *names;
  454. int p=0;
  455. FILE *fptr;
  456. record_count=0;
  457. if((names=(struct player*) calloc(100,sizeof(struct player)))==NULL)
  458.     {
  459.     od_printf("\n\rNot enough memory for Player.lst");
  460.     WaitForEnter();
  461.     }
  462. else
  463. {
  464.     fptr = OpenExclusiveFile("player.lst", "rb", WAIT_FOR_FILE);
  465.     while( fread(&names[record_count],sizeof(names[record_count]),1,fptr)==1)
  466.         record_count++;
  467.        fclose(fptr);
  468.        }
  469.  
  470.                //check for a match of name[p].bbs_name
  471.               //against door_sys_name
  472. for(p=0;p<record_count;p++)
  473.     { //begin for
  474.     od_kernal();  //run kernal to keep contact with remote user
  475.     if (stricmp (door_sys_name,names[p].bbs_name) ==0)
  476.         {  //begin if
  477.         playerfound=1;     //player is found...
  478.         strcpy(current.name,names[p].name);
  479.         strcpy(current.bbs_name,names[p].bbs_name);
  480.         current.living=atoi(names[p].living);
  481.         strcpy(current.killer,names[p].killer);
  482.         current.location=atoi(names[p].location);
  483.         current.lifepoints=atol(names[p].lifepoints);
  484.         current.lifepointsttl=atol(names[p].lifepointsttl);
  485.  
  486.         strcpy(current.weapon,names[p].weapon);
  487.         current.weapon_energy=atol(names[p].weapon_energy);
  488.         current.weapon_strength=atoi(names[p].weapon_strength);
  489.         current.max_packs=atol(names[p].max_packs);
  490.  
  491.         current.weapon_status=atoi(names[p].weapon_status);
  492.         current.weapon_cost=atol(names[p].weapon_cost);
  493.  
  494.         strcpy(current.armor,names[p].armor);
  495.         current.armor_strength=atol(names[p].armor_strength);
  496.         current.armor_status=atoi(names[p].armor_status);
  497.         current.armor_cost=atol(names[p].armor_cost);
  498.  
  499.         current.credits=atol(names[p].credits);
  500.         current.bank_credit=atol(names[p].bank_credit);
  501.  
  502.         current.pod=atoi(names[p].pod);
  503.  
  504.         current.ship=atoi(names[p].ship);
  505.         strcpy(current.ship_name,names[p].ship_name);
  506.         current.ship_type=atoi(names[p].ship_type);
  507.         current.mt=atoi(names[p].mt);
  508.         current.arkon_bomb=atoi(names[p].arkon_bomb);
  509.  
  510.         current.level=atoi(names[p].level);
  511.         current.kills=atoi(names[p].kills);
  512.         current.experience=atol(names[p].experience);
  513.         current.droids=atoi(names[p].droids);
  514.         current.passkey=atoi(names[p].passkey);
  515.  
  516.         current.on_off=atoi(names[p].on_off);
  517.         current.sickbay_closed=atoi(names[p].sickbay_closed);
  518.         current.bank_closed=atoi(names[p].bank_closed);
  519.         current.pickpocket=atoi(names[p].pickpocket);
  520.         current.tipcnt=atoi(names[p].tipcnt);
  521.         current.owns=atoi(names[p].owns);
  522.         current.fights=atoi(names[p].fights);
  523.         current.last_played=atoi(names[p].last_played);
  524.  
  525.         p=record_count;
  526.         }    //end if
  527.      else playerfound=0;
  528.     }  //end for
  529. free(names);
  530. }
  531.  
  532. void update_player_file(void) //update the changes to the file.
  533. {
  534. int p=0;
  535.  
  536.  
  537. struct player *names;
  538.  
  539. FILE *fptr;
  540. if((names=(struct player*) calloc(100,sizeof(struct player)))==NULL)
  541.     {
  542.     od_printf("\n\rNot enough memory for player.lst");
  543.     WaitForEnter();
  544.     }
  545. else
  546. {
  547.                //READ player file
  548.     fptr = OpenExclusiveFile("player.lst", "rb", WAIT_FOR_FILE);
  549.     while( fread(&names[p],sizeof(names[p]),1,fptr)==1)
  550.          {
  551.           od_kernal();
  552.           if (stricmp (names[p].bbs_name,current.bbs_name) ==0)
  553.         {
  554.             //when found copy data to text file
  555.           sprintf(names[p].on_now, "%d",current.on_now);
  556.           strncpy(names[p].name,current.name,sizeof(current.name));
  557.           strncpy(names[p].bbs_name,current.bbs_name,sizeof(current.bbs_name));
  558.           sprintf(names[p].living, "%d", current.living);
  559.           strncpy(names[p].killer,current.killer,sizeof(current.killer));
  560.           sprintf(names[p].location, "%d",current.location);
  561.           sprintf(names[p].lifepoints, "%ld", current.lifepoints);
  562.           sprintf(names[p].lifepointsttl, "%ld", current.lifepointsttl);
  563.  
  564.           strncpy(names[p].weapon,current.weapon,sizeof(current.weapon));
  565.           sprintf(names[p].weapon_energy, "%ld", current.weapon_energy);
  566.           sprintf(names[p].weapon_strength, "%d", current.weapon_strength);
  567.           sprintf(names[p].max_packs, "%ld", current.max_packs);
  568.  
  569.           sprintf(names[p].weapon_status, "%d", current.weapon_status);
  570.           sprintf(names[p].weapon_cost, "%ld", current.weapon_cost);
  571.  
  572.           strncpy(names[p].armor,current.armor,sizeof(current.armor));
  573.           sprintf(names[p].armor_strength, "%ld", current.armor_strength);
  574.           sprintf(names[p].armor_status, "%d", current.armor_status);
  575.           sprintf(names[p].armor_cost, "%ld", current.armor_cost);
  576.  
  577.           sprintf(names[p].credits, "%ld", current.credits);
  578.           sprintf(names[p].bank_credit, "%ld", current.bank_credit);
  579.  
  580.           sprintf(names[p].pod,"%d",current.pod);
  581.  
  582.           sprintf(names[p].ship,"%d",current.ship);
  583.           strncpy(names[p].ship_name,current.ship_name,sizeof(current.ship_name));
  584.           sprintf(names[p].ship_type,"%d",current.ship_type);
  585.           sprintf(names[p].mt,"%d",current.mt);
  586.           sprintf(names[p].arkon_bomb,"%d",current.arkon_bomb);
  587.  
  588.           sprintf(names[p].level, "%d", current.level);
  589.           sprintf(names[p].experience, "%ld", current.experience);
  590.           sprintf(names[p].kills, "%d", current.kills);
  591.           sprintf(names[p].droids, "%d", current.droids);
  592.           sprintf(names[p].passkey, "%d", current.passkey);
  593.  
  594.           sprintf(names[p].on_off,"%d",current.on_off);
  595.           sprintf(names[p].sickbay_closed,"%d",current.sickbay_closed);
  596.           sprintf(names[p].bank_closed,"%d",current.bank_closed);
  597.           sprintf(names[p].pickpocket,"%d",current.pickpocket);
  598.           sprintf(names[p].tipcnt,"%d",current.tipcnt);
  599.           sprintf(names[p].owns,"%d",current.owns);
  600.           sprintf(names[p].fights,"%d",current.fights);
  601.           sprintf(names[p].last_played,"%d",current.last_played);
  602.           }
  603.         p++;
  604.          }
  605.        fclose(fptr);
  606.  
  607.  
  608.         //write the file
  609.     fptr = OpenExclusiveFile("player.lst", "wb", WAIT_FOR_FILE);
  610.     fwrite(names,sizeof(struct player), p, fptr);
  611.     fclose(fptr);
  612. free(names);
  613. }
  614. }
  615.     //exclusive file access routine by Brian Pirie, Opendoors 5.0
  616.     //Get his stuff, it's good!  Register it as well.
  617. FILE *OpenExclusiveFile(char *pszFileName, char *pszAccess, time_t Wait)
  618. {
  619.    FILE *pfFile;
  620.    time_t StartTime = time(NULL);
  621.  
  622.    for(;;)
  623.    {
  624.       /* Attempt to open file */
  625.       pfFile = fopen(pszFileName, pszAccess);
  626.  
  627.       /* If file was opened successfuly, then exit */
  628.       if(pfFile != NULL) break;
  629.  
  630.       /* If open failed, but not due to access failure, then exit */
  631.       if(errno != EACCES) break;
  632.  
  633.       /* If maximum time has elapsed, then exit */
  634.       if(StartTime + Wait < time(NULL)) break;
  635.  
  636.       /* Give the OpenDoors kernel a chance to execute before trying again */
  637.       od_kernel();
  638.    }
  639.  
  640.    /* Return pointer to file, if opened */
  641.    return(pfFile);
  642. }
  643.  
  644. void WaitForEnter(void)
  645. {
  646.    od_printf("\n\r\n\r");  //display prompt
  647.    od_printf("`cyan`Press `green`[ENTER]`cyan` to continue.\n\r");
  648.    od_get_answer("\n\r");  //get a line feed or carriage return
  649. }
  650.  
  651. void More(void)
  652. {
  653.    od_printf("\n\r\n\r");
  654.    od_printf("`cyan`<ENTER>`cyan`\n\r");
  655.    od_get_answer("\n\r");
  656. }
  657.  
  658. void change(void)  //convert the character string to a formatted char string.
  659. {
  660. if(atoi(number)>10||atol(number)>10) //This way it doesn't show up with a 00 if under 10credits.
  661. {
  662. switch(strlen(number))
  663.     {        //it's ooooogly, but it works.  I'm sure there is a routine
  664.     case 0:  //built for this, but I couldn't find it.  Use it if you like.
  665.          //heck, I wish I would've learned pointers before doing this
  666.          //but, oh well.  Why change it now?  I got other things to do,
  667.          //like write comments all over the place, and really mess it up.
  668.         number[0]='\x0';
  669.     case 1:
  670.         number[1]='0';
  671.     case 2:
  672.         number[2]='\x0';
  673.     case 3:
  674.         sprintf(number,"%c%c%c",number[0],number[1],number[2]);
  675.         break;
  676.     case 4:
  677.         sprintf(number,"%c,%c%c%c",number[0],number[1],number[2],number[3]);
  678.         break;
  679.     case 5:
  680.         sprintf(number,"%c%c,%c%c%c",number[0],number[1],number[2],number[3],number[4]);
  681.         break;
  682.     case 6:
  683.         sprintf(number,"%c%c%c,%c%c%c",number[0],number[1],number[2],number[3],number[4],number[5]);
  684.         break;
  685.     case 7:
  686.         sprintf(number,"%c,%c%c%c,%c%c%c",number[0],number[1],number[2],number[3],number[4],number[5],number[6]);
  687.         break;
  688.     case 8:
  689.         sprintf(number,"%c%c,%c%c%c,%c%c%c",number[0],number[1],number[2],number[3],number[4],number[5],number[6],number[7]);
  690.         break;
  691.     case 9:
  692.         sprintf(number,"%c%c%c,%c%c%c,%c%c%c",number[0],number[1],number[2],number[3],number[4],number[5],number[6],number[7],number[8]);
  693.         break;
  694.     case 10:
  695.         sprintf(number,"%c,%c%c%c,%c%c%c,%c%c%c",number[0],number[1],number[2],number[3],number[4],number[5],number[6],number[7],number[8],number[9]);
  696.         break;
  697.     default:
  698.         sprintf(number,"%c%c%c,%c%c%c,%c%c%c,%c%c%c",number[0],number[1],number[2],number[3],number[4],number[5],number[6],number[7],number[8],number[9],number[10],number[11]);
  699.         break;
  700.     }
  701. }
  702. }
  703.  
  704.